#include "nsuc16x0.h"

__IO uint32_t uwTickCnt;
uint32_t uwTickFreq = 0;

/** @defgroup UTILS_Exported_Functions_Group1 NVIC LL Driver
 *  @brief    NVIC Configuration functions
 *
@verbatim
  ==================================================================================
                      ##### NVIC Configuration functions #####
  ==================================================================================
    [..]
      This section provides the LL driver functions allowing to configure NVIC module

@endverbatim
  * @{
  */

/**
  * @brief  Set the priority grouping field (pre-emption priority and subpriority)
  *         using the required unlock sequence.
  * @param  PriorityGroup: The priority grouping bits length.
  *         This parameter can be one of the following values:
  *         @arg NVIC_PRIORITYGROUP_0: 0 bit  for pre-emption priority,
  *                                    3 bits for subpriority
  *         @arg NVIC_PRIORITYGROUP_1: 1 bit  for pre-emption priority,
  *                                    2 bits for subpriority
  *         @arg NVIC_PRIORITYGROUP_2: 2 bits for pre-emption priority,
  *                                    1 bits for subpriority
  *         @arg NVIC_PRIORITYGROUP_3: 3 bits for pre-emption priority,
  *                                    0 bit  for subpriority
  * @note   When the NVIC_PriorityGroup_0 is selected, IRQ pre-emption is no more possible.
  *         The pending IRQ priority will be managed only by the subpriority.
  * @retval None
  */
void LL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup) {
    /* Check the parameters */
    // assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));

    /* Set the PRIGROUP[10:8] bits according to the PriorityGroup parameter value */
    NVIC_SetPriorityGrouping(PriorityGroup);
}


/**
  * @brief  Set the priority of an interrupt.
  * @param  IRQn: External interrupt number.
  *         This parameter can be an enumerator of IRQn_Type enumeration
  * @param  PreemptPriority: The pre-emption priority for the IRQn channel.
  *         This parameter can be a value between 0 and 7
  *         A lower priority value indicates a higher priority
  * @param  SubPriority: the subpriority level for the IRQ channel.
  *         This parameter can be a value between 0 and 7
  *         A lower priority value indicates a higher priority.
  * @note   The table below gives the allowed values of the pre-emption priority and subpriority according
  *         to the Priority Grouping configuration performed by LL_NVIC_SetPriorityGrouping() function.
  *           =========================================================================================
  *             NVIC_PriorityGroup   | PreemptPriority | SubPriority |          Description
  *           =========================================================================================
  *            NVIC_PRIORITYGROUP_0  |        0        |     0-7     | 0 bit for pre-emption priority
  *                                  |                 |             | 3 bits for subpriority
  *           -----------------------------------------------------------------------------------------
  *            NVIC_PRIORITYGROUP_1  |       0-1       |     0-3     | 1 bit for pre-emption priority
  *                                  |                 |             | 2 bits for subpriority
  *           -----------------------------------------------------------------------------------------
  *            NVIC_PRIORITYGROUP_2  |       0-3       |     0-1     | 2 bits for pre-emption priority
  *                                  |                 |             | 1 bits for subpriority
  *           -----------------------------------------------------------------------------------------
  *            NVIC_PRIORITYGROUP_3  |       0-7       |      0      | 3 bits for pre-emption priority
  *                                  |                 |             | 0 bit for subpriority
  *           =========================================================================================
  * @retval None
  */
void LL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority) {
    uint32_t prioritygroup;

    /* Check the parameters */
    // assert_param(IS_NVIC_SUB_PRIORITY(SubPriority));
    // assert_param(IS_NVIC_PREEMPTION_PRIORITY(PreemptPriority));

    prioritygroup = NVIC_GetPriorityGrouping();

    NVIC_SetPriority(IRQn, NVIC_EncodePriority(prioritygroup, PreemptPriority, SubPriority));
}

/**
  * @brief  Enable a device specific interrupt in the NVIC interrupt controller.
  * @note   To configure interrupts priority correctly, the NVIC_PriorityGroupConfig()
  *         function should be called before.
  * @param  IRQn External interrupt number.
  *         This parameter can be an enumerator of IRQn_Type enumeration
  * @retval None
  */
void LL_NVIC_EnableIRQ(IRQn_Type IRQn) {
    /* Check the parameters */
    // assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
  
    /* Enable interrupt */
    NVIC_EnableIRQ(IRQn);
}

/**
  * @brief  Disable a device specific interrupt in the NVIC interrupt controller.
  * @param  IRQn External interrupt number.
  *         This parameter can be an enumerator of IRQn_Type enumeration
  * @retval None
  */
void LL_NVIC_DisableIRQ(IRQn_Type IRQn) {
    /* Check the parameters */
    // assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
  
    /* Disable interrupt */
    NVIC_DisableIRQ(IRQn);
}

/**
  * @brief  Initiate a system reset request to reset the MCU.
  * @retval None
  */
void LL_NVIC_SystemReset(void) {
    /* System Reset */
    NVIC_SystemReset();
}



